<?php
namespace app\home\controller;
use \think\Db;


class Salelog extends \think\Controller
{
  public function index(){
        //已售拍品展示
        $where = 'status = 2';
        input('category_id') and $category_id = input('category_id') or $category_id = 1;
        $category_id and $where .= ' and category_id = '.intval($category_id);
        $data = Db('baode_goods')->where($where)->order('is_hot asc ,id desc')->paginate(12);
        $saleArr = $data->items();
        $pages = $data->render();
        
        //已售拍品种类
        $classArr = Db('baode_goods_category')->select();
        return $this->allFetch(get_defined_vars());
    }
    
    public function info(){
        //拍品详情
        input('goods_id') and $goods_id = input('goods_id');
        $goodsInfo = Db('baode_goods')->where('id',intval($goods_id))->find();
        
        //点击量
        $click_num = $goodsInfo['click_num'] + 1;
        Db('baode_goods')->where('id', $goodsInfo['id'])->update(['click_num' => $click_num]);
        
        //热门推荐
        $where = 'status = 2 and category_id = '.intval($goodsInfo['category_id']).' and id != '.intval($goodsInfo['id']);
        $hotArr = Db('baode_goods')->where($where)->order('is_hot asc ,id desc')->limit(4)->select();
        
        //拍品种类
        $class = Db('baode_goods_category')->select();
        $group = array_column($class, 'names', 'id');
        return $this->allFetch(get_defined_vars());
    }
    
    
}
